/* Cmd.Java
 * 
 * This abstract command class is the root of the
 *  command heirarchy for the command patterns. 
 * 
 * Greg Warner
 * Derek Dupuis
 * Michael Dixey
 * Alex Schwartz
 */

import java.util.*;

public abstract class Cmd
{
   protected static HashMap< String, Cmd > cmds ;
   protected TourApp tourApp;
   protected String[ ] token;
   
   
   // initialize command recognition structure --
   // associate each command name with an object of that command type
   static
   {
      
      cmds = new HashMap< String, Cmd >();
      // create your command list here
      //example: cmds.put( "x", new CmdX( ) );
      cmds.put( "event", new EventCMD() );
      cmds.put( "tour", new TourCMD() );
      cmds.put( "offering", new TourOffCMD() );
      cmds.put( "provider", new ProviderCMD() );
      cmds.put( "service", new ServiceCMD() );
      cmds.put( "reservation", new ReservationCMD() );
      
   }
   
   /** Constructor only invoked from subclass constructors
     */
   protected Cmd( ){
   }
   
   /** Connect the Command hierarchy with the application
     * that contains the resources needed to process commands;
     */
   public void tourApp( TourApp app )
   {
      tourApp = app;
   }
   
   /** Supply the command tokens for further processing.
     */
   public void token( String[ ] t )
   {
      token = t;
   }
   
   /** Locate and return a subcommand object for the command name.
     */
   public static final Cmd findCmd( String key )
   {
      return cmds.get( key );
   }
   
   /** Abstract Method to carry out the behavior to implement the command.
     *  It is overriden in the ocmmand subclasses.
     */
   public abstract void exec( );
}